﻿namespace LazyMapper.Core
{
    public class PropertyMapping<TInput, TOutput, TType> : IPropertyMapping<TInput, TOutput>
    {
        private readonly IMappingOption<TInput, TType> _option;
        private readonly IPropertySetter<TOutput> _setter;

        public PropertyMapping(IMappingOption<TInput, TType> option, IPropertySetter<TOutput> setter)
        {
            _option = option;
            _setter = setter;

            // todo: Rolf Try to optimize 

        }

        public void Map(TInput input, TOutput output)
        {
            if (!_option.IsIgnored)
            {
                var obj = _option.GetObj(input);
                _setter.SetValue(output, obj);
            }
        }

        public string MemberName
        {
            get { return _setter.MemberName; }
        }

        public void Map(object input, object output)
        {
            Map((TInput)input, (TOutput)output);
        }
    }
}